<?php

/**
 * Classe modélisant les paramètres généraux de l'application
 */
class Config {

    // int
    private $idParam;
    // nom du parametre
    private $nom;
    // valeur du parametre
    private $valeur;

    function __construct($idParam, $nom, $mdp) {
        $this->idParam = $idParam;
        $this->nom = $nom;
        $this->mdp = $mdp;
    }

    public function getIdParam() {
        return $this->idParam;
    }

    public function setIdParam($idParam) {
        $this->idParam = $idParam;
    }

    public function getNom() {
        return $this->nom;
    }

    public function setNom($nom) {
        $this->nom = $nom;
    }

    public function getValeur() {
        return $this->valeur;
    }

    public function setValeur($valeur) {
        $this->valeur = $valeur;
    }

    public static function getConfig($nomConfig) {

        if ($nomConfig == null)
            return false;
        $dbInstance = Db::getInstance();
        $sql = 'SELECT * FROM config
                 WHERE nom = "' . $nomConfig . '" ';
        $resultat = $dbInstance->query($sql);
        $res = array();
        if ($resultat != null) {
            while ($ligne = $resultat->fetch(PDO::FETCH_OBJ)) {
                $res[] = $ligne;
            }
        }
        $obj = $res[0];
        $p = new Config($obj->id_param, $obj->nom, $obj->valeur);
        return $p;
    }

    

}

?>